package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.EmployeeService;
import com.sky.service.PaginationService;
import com.sky.service.impl.PaginationServiceImpl;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: sky-take-out
 * @package: com.sky.controller.admin
 * @className: PaginationController
 * @author: Eric
 * @description: TODO
 * @date: 2023/9/20 17:46
 * @version: 1.0
 */
@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分页管理")
public class PaginationController {

    @Autowired
    private PaginationService paginationService;

    /**
     * 页面
     *
     * @param categoryPageQueryDTO 分类页面查询d去
     * @return {@link Result}<{@link PageResult}>
     */
    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult pageResult = paginationService.page(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 添加分类
     *
     * @param categoryDTO 类别d到
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> addPagination(@RequestBody CategoryDTO categoryDTO){
        paginationService.addPagination(categoryDTO);
        return Result.success();
    }

    /**
     * 删除分类
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @DeleteMapping
    public Result<?> deleteClassification(Long id){
        paginationService.deleteClassificationById(id);
        return Result.success();
    }

    /**
     * 修改分类
     *
     * @param categoryDTO 类别d到
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping
    public Result<?> modifyClassification(@RequestBody CategoryDTO categoryDTO){
        paginationService.modifyClassification(categoryDTO);
        return Result.success();
    }

    /**
     * 更改状态
     *
     * @param id     id
     * @param status 状态
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/status/{status}")
    public Result<?> changeStatus(Long id, @PathVariable Integer status){
        paginationService.changeStatus(id,status);
        return Result.success();
    }

    /**
     * 按类型查询
     *
     * @param type 类型
     * @return {@link Result}
     */
    @GetMapping("/list")
    public Result queryByType(Integer type){
        List<Category> categoryList = paginationService.queryByType(type);
        return Result.success(categoryList);
    }
}
